﻿@using BrnMall.Web.StoreAdmin.Models
@model BrnMall.Web.StoreAdmin.Models.WidgetConfigListModel

@section header{
<title>小程序定制</title>
    <link type="text/css" rel="stylesheet" href="/admin_store/css/site.css"/>
    <script type="text/javascript" src="/admin_store/scripts/jquery.js"></script>
    <script type="text/javascript" src="/admin_store/scripts/jquery.validate.js"></script>
    <script type="text/javascript" src="/admin_store/scripts/jquery.validate.unobtrusive.js"></script>
    <link type="text/css" rel="stylesheet" href="/components/webuploader/webuploader.css"/>
    <script type="text/javascript" src="/components/webuploader/webuploader.js"></script>
    <link href="/components/jbox/Skins/Default/jbox.css" rel="stylesheet" type="text/css"/>
    <script type="text/javascript" src="/components/jbox/jquery.jBox-2.3.min.js"></script>
    <script type="text/javascript" src="/admin_store/scripts/showlist.js"></script>
    <script type="text/javascript" src="/components/my97datepicker/WdatePicker.js"></script>
    <script type="text/javascript" src="/admin_store/scripts/selectlist.js"></script>
    <script type="text/javascript" src="/admin_store/scripts/WidgetConfig.js"></script>
<script type="text/javascript">
    var type="@Model.configModel.LinkType";
    var linkValue='@Model.configModel.LinkValue';

    $(function () {
        load();
        var uploader = WebUploader.create({
            pick: '.uploadBut',
            auto: true,
            swf: '/components/webuploader/Uploader.swf',
            server: '/storeadmin/tool/upload?operation=uploadwidgetimage',
            fileVal: 'upload',
            accept: {
                title: 'Images',
                extensions: '@ViewData["allowImgType"]',
                mimeTypes: '*'
            },
            fileSingleSizeLimit: @ViewData["maxImgSize"]
            });

        uploader.on('uploadProgress', function(file, percentage) {
            $(".uploadPreview").html("上传中...");
        });

        uploader.on('uploadSuccess', function(file, response) {
            var data = response._raw;
            if (data == "-1")
                $(".uploadPreview").html('图片不能为空');
            else if (data == "-2")
                $(".uploadPreview").html('图片类型不允许');
            else if (data == "-3")
                $(".uploadPreview").html('图片太大');
            else {
                $(".uploadPreview").html("<img src=\"@WorkContext.ImageCDN/upload/store/@WorkContext.StoreId/widget/" + data + "\"  />");
                $("#ShowImg").val(data);
            }
        });

        uploader.on('uploadError', function(file) {
            $(".uploadPreview").html("上传失败");
        });
    });

    function load(){
        var isShow= "@Model.configModel.IsShow";
        var showImg="@Model.configModel.ShowImg";
        loadLinkValue();
        if(showImg!='')
            $(".uploadPreview").html("<img src=\"@WorkContext.ImageCDN/upload/store/@WorkContext.StoreId/widget/" + showImg + "\"  />");

        if(isShow=='True')
            $("#IsShow").attr("checked",true);
        else
            $("#IsShow").attr("checked",false);
    }

    function loadLinkValue(){
        if(linkValue=="")return;
        linkValue=JSON.parse(linkValue);
        //商品特征
        if (type === "productattr") {
            var sel=$_2("ProductAttr");
            for(var i=0;i<sel.options.length;i++){
                if (linkValue.Id == "hot" && sel.options[i].text=="热销")
                    sel.selectedIndex=i;
                if (linkValue.Id == "new" && sel.options[i].text=="新品")
                    sel.selectedIndex=i;
                if (linkValue.Id == "best" && sel.options[i].text=="精品")
                    sel.selectedIndex=i;
            }
        }
        //展示类型
        var displayType='@Model.configModel.DisplayType';
        var sel=$_2("DisplayType");
        for(var i=0;i<sel.options.length;i++){
            if ( sel.options[i].value==displayType)
                sel.selectedIndex=i;
        }
    }

    function $_2(id){
        return document.getElementById(id);
    }


</script>

}

@section body{
    <h1 class="rightH1">
        小程序网站 > 首页定制 > <span class="rightH1-cur">首页商品</span>
        <div class="right">
            <a href="@Html.Raw(ViewData["referer"].ToString())" class="menuBT">
                <img src="/admin_store/images/goback.jpg"/>返回列表</a>
            <div class="clear">
            </div>
        </div>
        <div class="clear">
        </div>
    </h1>
    <div class="table_top">
    </div>
    <div class="dataList">
        <table width="100%">
            <thead>
            <tr>

                <th width="100" align="left">
                    编号
                </th>
                <th width="200" align="left">
                    标题
                </th>
                @*<th width="140" align="left" style="display:none">
                    展示图片
                </th>*@
                <th width="150" align="center">
                    链接类型
                </th>
                <th align="center">
                    链接对象
                </th>
                @*<th align="center" style="display:none">
                    展示类型
                </th>*@
                <th align="center">
                    展示数量
                </th>
                <th width="140" align="center">
                    排序
                </th>
                <th width="140" align="left">
                    管理操作
                </th>
            </tr>
            </thead>
            <tbody>
            @foreach (WidgetConfigModel info in Model.Config)
            {
                <tr>

                    <td>@info.CId
                    </td>
                    <td>@info.ShowName
                    </td>
                    @*<td style="display:none">
                        <img height="40" width="40" src="@WorkContext.ImageCDN/upload/store/@WorkContext.StoreId/widget/@info.ShowImg"/>
                    </td>*@
                    <td align="center">
                        @if (info.LinkType == "product")
                        {
                            <span class="mainimgspan">商品</span>
                        }
                        else if (info.LinkType == "store_class")
                        {
                            <span class="mainimgspan">店铺商品分类</span>
                        }
                        else if (info.LinkType == "news")
                        {
                            <span class="mainimgspan">内容</span>
                        }
                        else if (info.LinkType == "news_type")
                        {
                            <span class="mainimgspan">内容分类</span>
                        }
                        else if (info.LinkType == "page")
                        {
                            <span class="mainimgspan">页面</span>
                        }
                        else if (info.LinkType == "productattr")
                        {
                            <span class="mainimgspan">商品特征</span>
                        }
                    </td>
                    <td align="center">
                        <span class="mainimgspan">@info.LinkValue.Name</span>
                    </td>
                    
                    @*<td align="center" style="display:none">
                        @if (info.DisplayType == 1)
                        {
                            <span class="mainimgspan">小图列表</span>
                        }
                        else if (info.DisplayType == 2)
                        {
                            <span class="mainimgspan">大图列表</span>
                        }
                        else if (info.DisplayType == 3)
                        {
                            <span class="mainimgspan">双图列表</span>
                        }
                    </td>*@
                    <td align="center">
                        <span class="mainimgspan">@info.DisplayCount</span>
                    </td>
                    <td align="center">
                        <input type="text" url="@Url.Action("ChangeWidgetConfigSort", new {cid = info.CId})" value="@info.DisplayOrder" class="sortinput unselectedsortinput"/>
                    </td>
                    <td>
                        <a href="@Url.Action("WidgetConfigList", new {cid = info.CId,code= Model.Widget.Code })" url="@Url.Action("WidgetConfigList", new {cid = info.CId,code= Model.Widget.Code })" }>修改</a>
                        <span class="btn-line">|</span>
                        <a href="#" url="@Url.Action("DeleteWidgetConfig","store", new {cid = info.CId})" class="ajaxdeleteOperate" }>删除</a>
                    </td>
                </tr>
            }
            </tbody>
        </table>
    </div>
    <div class="table_bottom bg">
    </div>
    @using (Html.BeginForm("AddWidgetConfig", "PC"))
    {
        @Html.HiddenFor(x => x.Code)
        <input id="linktype" name="linktype" value="productattr" type="hidden" />
        <div class="addTable">
            <table width="100%">
                <tbody>

                <tr>
                    <td width="66px" align="right">标题：</td>
                    <td style="padding-left: 10px;"><input type="text" size="50" id="ShowName" name="ShowName" value="@Model.configModel.ShowName"/></td>
                </tr>
                <tr style="display:none;">
                    <td width="66px" align="right">展示图片：</td>
                    <td style="padding-left: 10px;">
                        <input type="hidden" name="WId" id="WId" value="@Model.Widget.WId"/>
                        <div class="upload">
                            <div class="uploadPreview">暂无图片</div>
                            <div class="left">
                                <div class="uploadProgressBar"></div>
                                <div class="uploadBut">选择图片</div>
                            </div>

                            <div class="clear"></div>
                            <div class="left">@Model.UploadImageTips</div>
                        </div>
                        <input type="hidden" name="ShowImg" id="ShowImg" value="@Model.configModel.ShowImg"/>
                    </td>
                </tr>

                <tr>
                    <td align="right">商品特征:</td>
                    <td style="padding-left: 10px;">
                        <select id="ProductAttr" name="ProductAttr">
                            <option value="" selected>请选择</option>
                            <option value="new">新品</option>
                            <option value="hot">热销</option>
                            <option value="best">精品</option>
                        </select>
                    </td>
                </tr>
                <tr style="display:none;">
                    <td align="right">展示类型:</td>
                    <td style="padding-left: 10px;">
                        <select id="DisplayType" name="DisplayType">
                            <option value="0">请选择</option>
                            <option value="1" selected>小图列表</option>
                            <option value="2">大图列表</option>
                            <option value="3">双图列表</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td align="right">展示数量:</td>
                    <td style="padding-left: 10px;">
                        <input type="text" id="DisplayCount" name="DisplayCount" value="@Model.configModel.DisplayCount" class="input" size="10"/>
  
                    </td>
                </tr>
                <tr>
                    <td align="right">排序：</td>
                    <td style="padding-left: 10px;"><input type="text" name="DisplayOrder" id="DisplayOrder" value="@Model.configModel.DisplayOrder" class="input" size="10"/></td>
                </tr>
                <tr>
                    <td align="right">是否显示:</td>
                    <td style="padding-left: 10px;">@Html.CheckBox("IsShow", true)</td>
                </tr>
                <tr>
                    <td align="right">
                    </td>
                    <td>
                        @if (Model.configModel != null && Model.configModel.CId > 0)
                        {
                            <input type="hidden" name="CId" value="@Model.configModel.CId" />
                            <input type="image" id="addImg" style="margin: 0px; padding: 0px;" src="/admin_store/images/b.jpg" />
                        }
                        else
                        {
                            <input type="hidden" name="CId" value="0" />
                            <input type="image" id="addImg" style="margin: 0px; padding: 0px;" src="/admin_store/images/a.jpg" />
                        }       
                        <script type="text/javascript">
                            $("#addImg").click(function() {                               

                                if ($("#ShowName").val() === "") {
                                    alert("名称不能为空");
                                    return false;
                                }
                                if ($("#linktype").val() === "") {
                                    alert("链接不能为空");
                                    return false;
                                }
                                if($("#DisplayCount").val()==""){
                                    alert("展示数量不能为空");
                                    return false;
                                }
                                if(isNaN($("#DisplayCount").val())){
                                    alert("展示数量必须是数字");
                                    return false;
                                }
                                if( parseInt($("#DisplayCount").val())<1){
                                    alert("展示数量必须大于0");
                                    return false;
                                }        
                                $(this).parents("form").submit();
                                return false;
                             
                            });
                        </script>
                    </td>
                </tr>
                </tbody>
            </table>
        </div>
    }
}